package com.itkjb.leisurely.resource.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itkjb.leisurely.core.base.BaseConstants;
import com.itkjb.leisurely.core.base.BaseDto;
import com.itkjb.leisurely.core.base.BaseResult;
import com.itkjb.leisurely.core.base.controller.BaseController;
import com.itkjb.leisurely.resource.sys.model.SysStationModel;
import com.itkjb.leisurely.resource.sys.service.ISysStationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;
/**
 * <p>
 * 岗位 接口层
 * </p>
 *
 * @author itkjb.com
 * @since 2020-08-11
 */
@RestController
@RequestMapping("/sys/sys-station")
@Api(value="岗位",tags={"岗位相关接口"})
public class SysStationController extends BaseController<SysStationModel,ISysStationService> {

    /**
     * 获取岗位列表
     * @param param 查询通用参数
     * @param model 特定条件参数
     * @param request
     * @param response
     * @return
     */
    @GetMapping
    @ApiOperation(value="获取岗位列表",notes="支持分页参数")
    @PreAuthorize("hasAnyAuthority('SysStation','SysStation:query') || hasRole('"+ BaseConstants.ADMINISTRATOR_ROLE_CODE +"') ")
    public BaseResult<IPage<SysStationModel>> page(BaseDto param, SysStationModel model, HttpServletRequest request, HttpServletResponse response){
        BaseResult<IPage<SysStationModel>> res = new BaseResult<>();
        res = super.page(param, model);
        return res;
    }

    /**
     * 获取岗位列表
     * @param param 查询通用参数，分页参数不可用
     * @param model 特定条件参数
     * @param request
     * @param response
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value="获取岗位列表",notes="不支持分页")
    @PreAuthorize("hasAnyAuthority('SysStation','SysStation:query') || hasRole('"+ BaseConstants.ADMINISTRATOR_ROLE_CODE +"') ")
    public BaseResult<List<SysStationModel>> list(BaseDto param,SysStationModel model, HttpServletRequest request, HttpServletResponse response){
        BaseResult<List<SysStationModel>> res = new BaseResult<>();
        model.setStatus(1);
        return super.list(param, model);
    }

    /**
     * 新增岗位
     * @param param
     * @param request
     * @param response
     * @return
     */
    @PostMapping
    @ApiOperation(value="新增岗位",notes="")
    @PreAuthorize("hasAnyAuthority('SysStation:add') || hasRole('"+ BaseConstants.ADMINISTRATOR_ROLE_CODE +"') ")
    public BaseResult<SysStationModel> add(@Valid @RequestBody SysStationModel param, HttpServletRequest request, HttpServletResponse response){
        BaseResult<SysStationModel> res = new BaseResult<>();
        res = super.add(param);
        return res;
    }

    /**
     * 获取岗位详情
     * @param id
     * @param response
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value="获取岗位详情",notes="")
    @ApiParam(name = "id",type = "Serializable",required = true)
    @PreAuthorize("hasAnyAuthority('SysStation:info') || hasRole('"+ BaseConstants.ADMINISTRATOR_ROLE_CODE +"') ")
    public BaseResult<SysStationModel> info(@PathVariable("id") Serializable id, HttpServletRequest request, HttpServletResponse response){
        BaseResult<SysStationModel> res = new BaseResult<>();
        res = super.info(id);
        return res;
    }

    /**
     * 修改岗位
     * @param param
     * @param request
     * @param response
     * @return
     */
    @PutMapping
    @ApiOperation(value="修改岗位",notes="")
    @PreAuthorize("hasAnyAuthority('SysStation:edit') || hasRole('"+ BaseConstants.ADMINISTRATOR_ROLE_CODE +"') ")
    public BaseResult<SysStationModel> edit(@RequestBody SysStationModel param,HttpServletRequest request, HttpServletResponse response){
        BaseResult<SysStationModel> res = new BaseResult<>();
        res =  super.edit(param);
        return res;
    }

    /**
     * 删除岗位
     * @param ids
     * @param request
     * @param response
     * @return
     */
    @DeleteMapping
    @ApiOperation(value="删除岗位",notes="注意参数是数字，就算单个，也要以数字的形式传递")
    @PreAuthorize("hasAnyAuthority('SysStation:del') || hasRole('"+ BaseConstants.ADMINISTRATOR_ROLE_CODE +"') ")
    public BaseResult<SysStationModel> delete(@RequestBody String[] ids, HttpServletRequest request, HttpServletResponse response){
        BaseResult<SysStationModel> res = new BaseResult<>();
        res = super.delete(ids);
        return res;
    }

}

